package com.czy.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 统一响应封装类
 *
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private Integer code; //状态码
    private String message; // 返回信息
    private T data; // 返回数据


    //没有返回值的成功封装
    public static <T> Result<T> success() {
        Result<T> result = new Result();
        result.code = 200;
        result.message = "success";
        return result;
    }

    //成功封装
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.data = data;
        result.code = 200;
        result.message = "success";
        return result;
    }

    //错误
    public static <T> Result<T> error(Integer code, String msg) {
        Result result = new Result<>();
        result.message = msg;
        result.code = code;
        return result;
    }
}